#include "init.h"

void main(void)
{
    uint8_t resets_val;
    
#if (CONFIG_USING_WDOG == 1)
    /* enable watchdog at start */
    WDOG_ENABLE();
#else
    WDOG_DISABLE();
#endif
    init();

    IRQ_ENABLE();

    resets_val = RESETS;
    RESETS = 0;
    debug_print("reset: reason = %x\n", resets_val);

    while (1)
    {
        if (g_tick_expired_10) {
            key_handle_10ms();
        #if (CONFIG_APP_USE_DFU == 1)
            dfu_handle_10ms();
        #endif
            g_tick_expired_10 = 0;
        }
        if (g_tick_expired_100) {
            io_test_handle_100ms();

            key_test_handle_100ms();

            /* Clear UI status */
            event_clear_all_ui_mask();
            g_tick_expired_100 = 0;
        }
        if (g_tick_expired_500) {
            /** TODO: **/
            g_tick_expired_500 = 0;
        }
        if (g_tick_expired_1000) {
            debug_output_1000ms();
            WDOG_KEEP_ALIVE();
            
            g_tick_expired_1000 = 0;
        }

        pm_handle_busy_loop();
        
        CPU_IDLE();
    }
}
